'''
Created on Sep 22, 2012

@author: Thomas Dao
'''
from datetime import datetime
from entity.entity import Article, Board, Note
from google.appengine.ext import ndb
from kid import util
from operator import attrgetter
from web import settings
import logging

@ndb.tasklet
def get_all_async(user_key, **q_options):
    qry = Note.query(Note.user == user_key).order(-Note.created_time)
    notes = yield qry.fetch_async(**q_options)
    raise ndb.Return(notes)

@ndb.tasklet
def get_by_boards(board_keys, **q_options):
    logging.info(board_keys)
    if len(board_keys) > 0:
        qry = Note.query(Note.board.IN(board_keys)).order(-Note.created_time)
        notes = yield qry.fetch_async(**q_options)
    else:
        notes = None
        
    raise ndb.Return(notes)